﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KP_CommonLibrary.KP_CommonControls;
using KP_CommonLibrary.KP_CoreUI;
using KP_CommonLibrary;
using KP_CommonLibrary.Logs;
using KEEPER_BRR_13dotNET.BusinessLogic;

namespace KEEPER_BRR_13dotNET.Presentation
{
    public partial class FrmE_ThanhVienEdit : KP_CommonLibrary.KP_CoreUI.KP_EditListItem
    {
        public string HoSoRec { get; set; }
        public FrmE_ThanhVienEdit()
        {
            InitializeComponent();
        }
        #region Override Base Class
        public override void InitData(DataRow row)
        {
            row["Ma_ThanhVien"] = Guid.NewGuid();
            //1 Thêm,2 Sửa, 3 Xóa
            row["Loai"] = 1;
            base.InitData(row);
        }
        public override void SaveAndNew()
        {
            string state = "Lưu thông tin\n";
            try
            {
                state = "Kết thúc cập nhật\n";
                EndEdit();
                state = "Kiểm tra dữ liệu\n";
                if (ValidateAll())
                {
                    state = "Lưu thông tin\n";                    
                    ParentBinding.Refresh();
                    FormState = FormState.Unspecified;
                    state = "Khởi tạo bản ghi mới\n";
                    AddNew(ParentBinding);
                }
            }
            catch (Exception ex)
            {
                KPMessageBox.Show(state + ex.Message, KP_SYS_VARIABLE.M_KEEPER_VER, KPMessageBoxButton.OK, KPMessageBoxIcon.Error);
                //Log vao log
            }
        }
        public override void SaveAndClose()
        {
            string state = "";
            try
            {

                state = "Kiểm tra dữ liệu\n";
                if (ValidateAll())
                {
                    state = "Kết thúc cập nhật\n";
                    EndEdit();

                    state = "Lưu dữ liệu\n";
                    ParentBinding.Refresh();
                    // CurrentRow.AcceptChanges();
                    FormState = FormState.Unspecified;
                    Close();
                }
            }
            catch (Exception ex)
            {
                KPMessageBox.Show(state + ex.Message, KP_SYS_VARIABLE.M_KEEPER_VER, KPMessageBoxButton.OK, KPMessageBoxIcon.Error);
                //Log vao log
            }
        }
        public override void CustomWriteData(DataRow row)
        {
            if (row.IsNull("Stt_Rec"))
                row["Stt_Rec"] = HoSoRec;

            base.CustomWriteData(row);

        }
        public override void LoadDependencyData()
        {
            cbGioi_Tinh.DataSource= BL_KPDictionary.GetGioiTinhTable();
            base.LoadDependencyData();
        }
        #endregion
    }
}
